
INS_DIR	:= ../../bin/

CFLAGS 		+= -Wall -fPIC -Werror -g -w -DDEBUG=1 -fmessage-length=0 -O2
CFLAGS		+= -I. -Idist -DHAVE_CONFIG_H

LDFLAGS		+= -Wl,--as-needed

LIB_SRCS := \
    pcre_chartables.c \
    dist/pcre_byte_order.c \
    dist/pcre_compile.c \
    dist/pcre_config.c \
    dist/pcre_dfa_exec.c \
    dist/pcre_exec.c \
    dist/pcre_fullinfo.c \
    dist/pcre_get.c \
    dist/pcre_globals.c \
    dist/pcre_jit_compile.c \
    dist/pcre_maketables.c \
    dist/pcre_newline.c \
    dist/pcre_ord2utf8.c \
    dist/pcre_refcount.c \
    dist/pcre_string_utils.c \
    dist/pcre_study.c \
    dist/pcre_tables.c \
    dist/pcre_ucd.c \
    dist/pcre_valid_utf8.c \
    dist/pcre_version.c \
    dist/pcre_xclass.c


LIB_OBJS := $(patsubst %.c,%.o,$(LIB_SRCS))

ifneq ($(strip $(TOOLS_BUILD_SHARED)),)
LIB	:= libpcre.so
else
LIB	:= libpcre.a
endif

TARGET	:= $(LIB)

all:$(TARGET)
	
$(LIB):$(LIB_OBJS)
ifneq ($(strip $(TOOLS_BUILD_SHARED)),)
	$(CC) -o $@ $^ -shared $(LDFLAGS)
	$(STRIP) $@
else
	$(AR) rc $@ $^
endif

%.o:%.c
	$(CC) $(CFLAGS) -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o $@ $<

%.o:%.cpp
	$(CXX) $(CXXFLAGS) -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o $@ $<

install:
	test -d $(INS_DIR) || install -m 755 -d $(INS_DIR)
	install -m 755 $(LIB) $(INS_DIR)

clean:
	-rm -rf $(LIB_OBJS) *.d $(TARGET)

.PHONY: all clean install
